import React, { Component } from 'react'
import './app.less'
import 'windi.css';
import { createStore,Store } from 'redux';
import { Provider } from 'react-redux'
import reducer from "./store/reducers";
import { setData } from './store/actions/app';
import Taro from "@tarojs/taro";
import "./scss/var.scss"


Taro.cloud.init(
  {
    env: 'one-applocation-3gjwlquh7eb2ca0e',
    traceUser: true,
  }
);
const store:Store<any> = createStore(reducer);

Taro.getSystemInfo({
  success: function (res) {
    store.dispatch(setData({
      type:"SET",
      res
    }))
  }
})


class App extends Component {
  componentDidMount () {
    this.onGetOpenid();
  }
  componentDidShow () {}
  componentDidHide () {}
  componentDidCatchError () {}
  async onGetOpenid () {
      //云函数获取openid
      // 调用云函数
     await  new Promise((resolve,reject)=>{
        Taro.cloud.callFunction({
          name: 'login',
          data: {},
          success: res => {
            console.log('[云函数] [login] user openid: ',res)
            resolve(res);
          },
          fail: err => {
            console.error('[云函数] [login] 调用失败', err)
            reject(err)
          }
        });
      })

   
     console.log("授权完成")

  }
  // this.props.children 是将要会渲染的页面
  render () {
    return (
       <Provider store={store}>
           {this.props.children}
       </Provider>
    )
  }
}


export default App
